<?php

namespace App\Admin\Forms\GoodsOrder;

use App\Exceptions\AdminInvalidRequestException;
use App\Models\User;
use Carbon\Carbon;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Godruoyi\Snowflake\Snowflake;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class GoodsOrderForm extends Form implements LazyRenderable
{
    use LazyWidget;

    private int $expire = 30;
    private int $state;
    private string $remark;
    private string $key;
    private  $payment;

    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return JsonResponse
     * @throws AdminInvalidRequestException
     */
    public function handle(array $input): JsonResponse
    {
        $ids = explode(',', $input['ids'] ?? null);

        return $this
            ->response()
            ->success(trans('admin.succeeded'))
            ->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {

        $this->radio('states', trans('order.fields.state'))->options([
            Order::PENDING => '通过',
            Order::REFUSE => '拒绝',
            Order::CANCEL => '取消',
            Order::SUCCESS => '成功',
        ])
            ->when(Order::PENDING, function (Form $form) {
                $form->select('payment_address_id', trans('payment-address.labels.PaymentAddress'))->options(
                    PaymentThirdPay::query()
                        ->open()
                        ->withdrawal(PaymentThirdPay::WITHDRAWAL_OPEN)
                        ->pluck('title','id')->toArray()
                );
            })
            ->required();
        $this->text('remark', trans('order.fields.remark'));
        $this->hidden('ids')->attribute('id', 'batch-ids');
    }



}
